package com.lilei.serialize;

import com.alibaba.fastjson.JSONObject;

public class FastJsonSerializer implements ISerializer {
    /*
        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.68</version>
        </dependency>
    不能序列化translate修饰的字段
     */
    @Override
    public <T> byte[] serialize(T obj) {
        return JSONObject.toJSONBytes(obj);
    }

    @Override
    public <T> T deserialize(byte[] data, Class<T> clazz) {
        return JSONObject.parseObject(new String(data), clazz);
    }
}
